package com.ticket.sass.admin.dto.input.banner;

import com.ticket.sass.admin.validator.InEnum;
import com.ticket.sass.common.entity.tenant.enums.JumpType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
import java.util.Map;

/**
 * @author ywb
 * @date 2024-04-30 11:04
 */
@Data
@ApiModel
public class BannerAddInput {
    @NotBlank(message = "标题不能为空")
    @ApiModelProperty(value = "标题")
    private String title;
    
    @NotBlank(message = "key不能为空")
    @ApiModelProperty(value = "云存储Key")
    private String key;
    
    @NotNull(message = "跳转类型不能为空")
    @ApiModelProperty(value = "跳转类型：0 不跳转，1 内部页面 2 小程序 3 网页")
    @InEnum(intValues = {0, 1, 2, 3})
    private Short jumpType;
    
    @ApiModelProperty(value = "跳转配置")
    private Map<String, Object> jumpConfig;
    
    @Valid
    @NotNull(message = "显示位置不能为空")
    @Size(min = 1, message = "显示位置不能为空")
    @ApiModelProperty(value = "显示位置：1 首页")
    private List<@InEnum(intValues = {1}, message = "显示位置不正确") Short> position;
    
    @AssertTrue(message = "跳转配置必须符合规范")
    public boolean isJumpConfig() {
        return  JumpType.Companion.valueOf(jumpType).isJumpConfigValid(jumpConfig);
    }
}
